/////////////////////////////////////////////////////////////////////////////
// Purpose:     Access to user information
// Author:      Jesus Gonzalez
// Modified by:
// Copyright:   (c) 2003-2013 Jesus Gonzalez <jgonzalez@gdr-sistemas.com>
// License:     BSD License
/////////////////////////////////////////////////////////////////////////////

#include "SmartLib/SysUser.h"
#include <unistd.h>
#include <pwd.h>

std::string SysUser::GetHomeDir()
{
	static uid_t saved_uid = (uid_t)-1;
	static std::string saved_dir;

	uid_t cur_uid = getuid();
	if( cur_uid != saved_uid )
	{
		saved_uid = cur_uid;
		struct passwd *pw = getpwuid(cur_uid);
		saved_dir = pw->pw_dir;
	}

	return saved_dir;
}
